<?php namespace Common\Controller;

use Think\Controller;

class BaseController extends  Controller{

    public function __construct()
    {
        parent::__construct();
        if(method_exists($this,'__init'))
        {
            $this->__init();
        }

        if(!session('uid')){
            $this->error('请登录！',u('admin/login/login'));
        }
    }


    public function store(model $Model,$data,$url,\Closure $callback=null)
    {

//      $Model  = new ConfigModel(), $data =I('post.');
        $res = $Model->store($data);
        if($res[ 'valid' ] == 'success' && $callback instanceof \Closure)
        {
            $callback($res);
        }
        $this->message($res,$url);
    }

    public function message($res,$url){
        if($res['valid']=='success'){
            $this->success($res['msg'],$url);exit;
        }else{
            $this->error($res['msg'],$url);exit;
        }
    }
}
